;
define(function (require, exports, module) {
    var base = require("base");
    var init = function (num) {
        require("../topMenu/topMenu.css"),
        $("#header").html(require("../topMenu/topMenu.html"));
        initEvent(num);
        loadCurrentUserInfo();
    	inquireCurrentOperationList();
    };
    var inquireCurrentOperationList = function(){
        base.fnAjax({
            action: 'inquireCurrentOperationList.json',
            async:false,
            version: 'v3.0',
            fnSuccess: function (data) {
                if (data.status == 200) {
                    for(var i=0;i<data.datas.length;i++){
                        var permission = data.datas[i];
                        var permissionId = permission.permissionId;
                        $.each($("#header").find("li,a"), function() {
                        	var $this = $(this);
                        	if($this.attr("permissionId") == permissionId){
                        		$this.removeClass("none");
                        	}
                        });
                    }
                } else {
                    base.alert(3, data.message);
                }
            }
        });
    };
    var loadCurrentUserInfo = function () {
        base.fnAjax({
            action: 'inquireCurrentUserInfo.json',
            async:false,
            version: 'v3.0',
            fnSuccess: function (data) {
                if (data.status == 200) {
                    $('#currentUserName').text(data.datas[0].fullName);
                } else {
                    base.alert(3, data.message);
                }
            }
        });
    }
    
    var logout1 = function () {
        base.fnAjax({
            action: 'logout1.json',
            async:false,
            version: 'v3.0',
            fnSuccess: function (data) {
                if (data.status == 200) {
                	base.clearData("sid");//清除sessionUuid
		            base.clearData("appKey");
		            base.openUrl("../login/login.html");
                } else {
//                  base.alert(3, data.message);
					base.clearData("sid");//清除sessionUuid
		            base.clearData("appKey");
		            base.openUrl("../login/login.html");
                }
            }
        });
    }

    var initEvent = function (num) {
        $(".topMenu_hover:eq(" + num + ")").addClass("topMenu_selected");
        $("ul .topMenu_hover").on("click", function () {
            var location = $(this).children().attr("href");
            window.location.href = location;
        });
        // 退出登录
        $("#user_logout").click(function () {
        	logout1();
        });
        //下拉信息
        $(".leave").mouseenter(function () {
            $(".topMenu_user_set_menu").css("display", "none");
            var slideDown2 = $("#topMenu_userName_menu");
            slideDown2.css("display", "block");

            $(".leave").unbind("mouseleave").mouseleave(function () {
                time = setTimeout(function () {
                    slideDown2.css("display", "none");
                }, 2000);
            })
            slideDown2.unbind("mouseenter").mouseenter(function () {
                clearTimeout(time);
            });
            slideDown2.unbind("mouseleave").mouseleave(function () {
                slideDown2.css("display", "none");
            });

        });
    };
    
    return {
        init: init
    }
});